
// 03myCenter/02sectorization/01myChange/myChange.js
var co = require('../../../resource/js/common.js')
var app = getApp()
var _this, _data

Page({

   /* 页面的初始数据*/
   data: {
      change: '',
      hasBiz:false
   },

   /*生命周期函数--监听页面加载*/
   onLoad: function(options) {
      _this = this
      _data = this.data
      this.get_new_balance()
      this.getBizList()
      console.log('userinfo=====',app.Data.userInfo)
   },

   onShow: function() {
      _this.setData({
         change: app.Data.userInfo.User_Balance
      })
   },
   //获取新的账户余额
   get_new_balance: function() {
      co.getJyhsApi('money/Recorduser/getBalance', {
         User_ID: app.Data.userInfo.User_ID
      }, function(res) {
         //console.log('res===b',res)
         //console.log('app.Data === a',app.Data)
         app.Data.userInfo.User_Balance = res.data.User_Balance
         wx.setStorageSync('userInfo', app.Data.userInfo)
         _this.setData({
            change: res.data.User_Balance
         })
      });
   },
   //前往充值页面
   recharge: function(e) {
      if (app.Data.userInfo.PayPassword_Is_Set == 0) {
         co.confirm('未设置支付密码', '取消', '前往设置', function(res) {
            if (res) {
               wx.navigateTo({
                  url: "/04myCenter/02set/02changePayPwd/changePayPwd",
               })
            }
         })
         return
      }
      var id = e.currentTarget.dataset.id
      var url_end = id == 1 ? 'recharge/recharge' : 'widthdraw/widthdraw'
      //console.log('url_end===', url_end)
      wx.navigateTo({
         url: '/04myCenter/01myWallet/01myChange/' + url_end
      })
   },

   // 跳转到我的银行卡页面
   bankCard: function() {
      wx.navigateTo({
         url: "/04myCenter/01myWallet/01myChange/bankCard/bankCard",
      })
   },
   //企业钱包
   enterpriseChage:function(){
      wx.navigateTo({
         url: '/04myCenter/01myWallet/myWallet',
      })
   },
   //获取企业列表
   getBizList: function () {
      var url = 'jyhs/Admin/getBizList'
      co.getShareApi(url, {
         User_ID: app.Data.userInfo.User_ID
      }, function (res) {
         if (res.code===0) {
            _this.setData({
               hasBiz:true
            })
         }else{
            _this.setData({
               hasBiz: false
            })
         }
      })
   },
})